import mysql.connector
import os


# 连接到MySQL数据库
conn = mysql.connector.connect(
    host="81.70.23.21",
    port="8306",
    user="root",
    password="jsti@2024",
    database="bid"
)
cursor = conn.cursor()

# 查询bid_source_database表中的内容
cursor.execute("SELECT id, content FROM bid_source_data")

# 获取查询结果
results = cursor.fetchall()

# 创建一个文件夹来保存txt文件
output_folder = "D:\\item\\ttt"
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# 将每条记录写入一个以id命名的txt文件
for row in results:
    file_name = f"{output_folder}//{row[0]}.txt"
    with open(file_name, "w") as f:
        for column in row:
            f.write(str(column) + "\n")
# 关闭数据库连接
cursor.close()
conn.close()
